package cn.pxs.dao;

import cn.pxs.entity.Content;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;


@Repository
public class ContentDao {
    @Autowired
    MongoTemplate mt;

    public Content findById(String id){
        Content c = mt.findById(id, Content.class);
        return c;
    }

    public Content add(Content c){
        Content save = mt.save(c);
        return save;
    }

    public void delById(String id){
        mt.findAndRemove(new Query(Criteria.where("id").is(id)),Content.class);
    }

}
